import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  // 添加服务器端口配置
  server: {
    port: 8080,
    // 添加代理配置
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => {
          console.log(`Proxy: Forwarding ${path} to ${path}`);  // 日志调试：显示转发路径
          return path;  // 不修改路径，保留/api前缀匹配后端
        },
        secure: false  // 如果后端是http，添加此项避免https检查
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
